package com.fanghaoran.view.user.notebookFrame;

import com.fanghaoran.entity.Words;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * @Author: win11
 * @Date: 2023/03/27/22:26
 * @Description: 用户间可互相查看的数据表格
 */
public class NoteBookTableModel extends AbstractTableModel {
    private final String[] columnNames = { "单词","释义" };
    private final List<Words> wordList;

    public NoteBookTableModel(List<Words> wordList) {
        this.wordList = wordList;
    }

    @Override
    public int getRowCount() {
        return wordList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Words word = wordList.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return word.getWord();
            case 1:
                return word.getTranslation();
            default:
                return null;
        }
    }


    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }
}
